package it.xiuxian.homepage.presenter


import com.lzy.okgo.OkGo
import it.xiuxian.homepage.bean.*
import it.xiuxian.homepage.fragment.HomePageFragment
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.bean.NewPersonBean
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.EncodeUtils
import it.xiuxian.xingqiu.bean.SuanLiBean
import org.json.JSONObject

class HomePageFragmentPresenter :BasePresenter<HomePageFragment>(){
    fun getHomePage(){
        OkGo.post<BaseBean<NewPersonBean>>(HttpConfig.BASE_URL+"/appuser/info")
            .execute(object : CallBackOption<BaseBean<NewPersonBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object :ILoadBind<BaseBean<NewPersonBean>>{
                    override fun excute(bean: BaseBean<NewPersonBean>) {
                        if(bean.code==0){
                            (mView as HomePageFragment).getXinXI(bean.data)
                        }
                    }
                }
            ))
    }
    fun getBanner(){
        OkGo.post<BaseBean<BannerBean>>(HttpConfig.BASE_URL+"/appbanner/list")
            .execute(object : CallBackOption<BaseBean<BannerBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object :ILoadBind<BaseBean<BannerBean>>{
                    override fun excute(bean: BaseBean<BannerBean>) {
                        if(bean.code==0){
                            (mView as HomePageFragment).setUI(bean.data)
                        }
                    }
                }
            ))
    }

    fun getZiXun(){
        OkGo.post<BaseBean<ZiXunBean>>(HttpConfig.BASE_URL+"/appzixun/shouyelist")
            .execute(object : CallBackOption<BaseBean<ZiXunBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object :ILoadBind<BaseBean<ZiXunBean>>{
                    override fun excute(bean: BaseBean<ZiXunBean>) {
                        if(bean.code==0){
                            (mView as HomePageFragment).setZiXun(bean.data)
                        }
                    }
                }
            ))
    }
     fun qiandao(){
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appqiandao/qiandao")
            .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as HomePageFragment).execute(
                object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        if(bean.code==0){

                            (mView as HomePageFragment).updateUI(bean.msg)
                        }
                    }
                }
            ))
    }
    fun getMonGongxian(){
        OkGo.post<BaseBean<MonGongXianBean>>(HttpConfig.BASE_URL+"/apppaihangbang/yuebang")
            .execute(object : CallBackOption<BaseBean<MonGongXianBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object : ILoadBind<BaseBean<MonGongXianBean>> {
                    override fun excute(bean: BaseBean<MonGongXianBean>) {
                        if(bean.code==0){
                           // (mView as HomePageFragment).setGongXian(bean.data)
                        }
                    }
                }
            ))
    }
    fun getZongGongxian(){
        OkGo.post<BaseBean<MonGongXianBean>>(HttpConfig.BASE_URL+"/apppaihangbang/zongbang")
            .execute(object : CallBackOption<BaseBean<MonGongXianBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object : ILoadBind<BaseBean<MonGongXianBean>> {
                    override fun excute(bean: BaseBean<MonGongXianBean>) {
                        if(bean.code==0){
                          //  (mView as HomePageFragment).setZong(bean.data)
                        }
                    }
                }
            ))
    }
    fun getList(pageNo:String,state:String){
        var json1 = JSONObject()
        json1.put("pageNo",pageNo)
            .put("sort",state)
        OkGo.post<BaseBean<SuanLiBean>>(HttpConfig.BASE_URL+"/appgongyiqiang/list")
            .params("encrypt", EncodeUtils.encodeAES(json1.toString()))
            .execute(object : CallBackOption<BaseBean<SuanLiBean>>() {}.loadBind(mView as HomePageFragment).execute(
                object : ILoadBind<BaseBean<SuanLiBean>> {
                    override fun excute(bean: BaseBean<SuanLiBean>) {
                        if(bean.code==0){
                            (mView as HomePageFragment).geData(bean.data)
                        }
                    }
                }
            ))
    }
}